package com.ssd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ssd.dto.TaskDetailsDto;
import com.ssd.entity.TaskDetails;
import com.ssd.mapper.TaskDetailsMapper;
import com.ssd.service.TaskDetailsService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * TaskDetailsServiceImpl 类
 *
 * @title:
 * @requirement:
 * @ClassName:
 * @author:首雯静
 * @creationTime:2024/12/20/17:01
 * @version: 1.0
 */
@Service
public class TaskDetailsServiceImpl extends ServiceImpl<TaskDetailsMapper, TaskDetails> implements TaskDetailsService {
    @Override
    public List<TaskDetails> getListByTaskId(Long taskId) {
        QueryWrapper<TaskDetails> qw = Wrappers.query();
        qw.eq("task_id",taskId);
        return baseMapper.selectList(qw);
    }

    @Override
    public boolean createTaskDetails(Long taskId, List<TaskDetailsDto> taskDetailsDtoList) {
        //转换数据类型
        List<TaskDetails> taskDetailsList = new ArrayList<>();
        for (TaskDetailsDto taskDetailsDto : taskDetailsDtoList) {
            TaskDetails taskDetails = new TaskDetails();
            taskDetails.setTaskId(taskId);
            taskDetails.setChannelCode(taskDetailsDto.getChannelCode());
            taskDetails.setExpectCapacity(taskDetailsDto.getExpectCapacity());
            taskDetailsList.add(taskDetails);
        }
        //批量保存数据
        boolean saved = this.saveBatch(taskDetailsList);
        return saved;
    }
}
